home *** CD-ROM | disk | FTP | other *** search
- Sub Command1_Click ()
- Dim doc As Object
-
- ' Copies the textbox into a new Word document
- ClipBoard.SetText text1.Text
- Set doc = CreateObject("word.basic")
- doc.FileNewDefault
- doc.EditPaste
-
- ' Creates / overwrites a new Word macro "Counter"
- doc.ToolsMacro "Counter", 0, 1
- doc.EditSelectAll
- doc.EditClear
- doc.Insert "Sub MAIN"
- doc.InsertPara
- doc.Insert "ToolsWordCount"
- doc.InsertPara
- doc.Insert "Dim dlg As ToolsWordCount"
- doc.InsertPara
- doc.Insert "GetCurValues dlg"
- doc.InsertPara
- doc.Insert "MsgBox ""Current word count:"" + dlg.Words"
- doc.InsertPara
- doc.Insert "End Sub"
- doc.FileClose 1
-
- ' Runs the macro, manipulates the return message (a hack)
- On Error Resume Next
- doc.ToolsMacro "Counter", 1, 0
- MsgBox Right$(Error$, Len(Error$) - 22)
-
- ' Cleans up
- doc.FileClose 2
- Set doc = Nothing
- End Sub
-